from router.chat_router import router as chat_router
from router.asr_router import router as asr_router
from router.keyword_router import router as keyword_router
from router.auth_router import router as auth_router
from router.admin_router import router as admin_router
from router.config_router import router as config_router
from router.history_router import router as history_router
from router.question_router import router as question_router
from router.external_router import router as external_router
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

# 初始化FastAPI应用
app = FastAPI(
    title="数字人管理系统",
    description="数字人管理系统后端API",
    version="1.0.0"
)

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 挂载静态文件服务
app.mount("/api/uploads", StaticFiles(directory="uploads"), name="uploads")

app.include_router(auth_router)
app.include_router(admin_router)
app.include_router(config_router)
app.include_router(history_router)
app.include_router(question_router)
app.include_router(external_router)
app.include_router(chat_router)
app.include_router(asr_router)
app.include_router(keyword_router)

if __name__ == "__main__":
    import uvicorn
    from dotenv import load_dotenv
    load_dotenv()
    import os

    uvicorn.run("main:app", host="0.0.0.0", port=int(
        os.getenv("BACKEND_PORT", 7001)))
